package com.mmlc.meimei.lichengkongjian.home;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.mmlc.inter.InterAdapter;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.network.responsebean.GoodsListResponseBean;
import com.mmlc.utils.ViewUtils;
import com.mmlc.utils.XUtils;

import java.util.List;

/**
 * Created by Administrator on 2016/7/14.
 */
public class ProductPreviewAdapter extends InterAdapter<GoodsListResponseBean.DataBean.GoodslistBean> {

    public ProductPreviewAdapter(Context context, List<GoodsListResponseBean.DataBean.GoodslistBean> datas) {
        super(context, datas);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_product_preview, viewGroup, false);

            holder.iv_avatar = ViewUtils.getView(view, R.id.iv_avatar);
            holder.tv_name = ViewUtils.getView(view, R.id.tv_name);

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        GoodsListResponseBean.DataBean.GoodslistBean product = datas.get(i);
        if (holder.iv_avatar != null && !ViewUtils.isEmpty(product.getGoods_name())) {
            XUtils.image(holder.iv_avatar, product.getImg_thumb());
        }

        if (holder.tv_name != null && !TextUtils.isEmpty(product.getGoods_name())) {
            holder.tv_name.setText(product.getGoods_name());
        }

        return view;
    }

    class ViewHolder {
        ImageView iv_avatar;
        TextView tv_name;
    }
}
